// ignore_for_file: prefer_final_fields, use_super_parameters, library_private_types_in_public_api

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'widgets/home_banner.dart';
import 'widgets/home_search.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // 生命周期
  @override
  void initState() {
    super.initState();
    _getData();
  }

  // 实例化
  Dio _dio = Dio(
      BaseOptions(baseUrl: 'http://smart-shop.itheima.net/index.php?s=/api/'));

  // 定义字典存储接口数据
  List _bannerList = [];

  // 获取数据
  _getData() async {
    Response res = await _dio.get('page/detail');
    setState(() {
      _bannerList = res.data['data']['pageData']['items'][1]['data'];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          '智慧商城',
          style: TextStyle(fontSize: 18, color: Colors.white),
        ),
        backgroundColor: Colors.red,
      ),
      body: ListView(
        children: [
          const HomeSearch(),
          HomeBanner(
            bannerList: _bannerList,
          )
        ],
      ),
    );
  }
}
